package com.example.spirngdemo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 */
public class Clouds {
    public int jump(int cloudSize , int[] cloudArray){
        if(cloudSize < 2 || cloudSize > 100){
            throw new RuntimeException("超出云范围");
        }
        if(cloudArray.length != cloudSize){
            throw new RuntimeException("云数量和云数组长度不对应");
        }
        if(cloudArray[0] == 1 || cloudArray[cloudSize-1] == 1){
            throw new RuntimeException("云数组不规范");
        }

        List<Integer> correctCloudList = new ArrayList<>();
        for (int i=0;i< cloudSize;){
            if(i == cloudSize -1 ){
                return correctCloudList.size();
            }
            if( i+2 >= cloudSize-1){
                correctCloudList.add(cloudSize-1);
                return correctCloudList.size();
            }
            if(cloudArray[i+2] == 1){
                i = i+1;
                correctCloudList.add(i);
                continue;
            }
            i = i+2;
            correctCloudList.add(i);
        }
        return correctCloudList.size();
    }

    public static void main(String[] args) {
        Clouds clouds = new Clouds();
        int[] cloudArray = {0,0,1,0,0,1,0};
        int jump = clouds.jump(7, cloudArray);
        System.out.println(7);
        System.out.println(Arrays.toString(cloudArray));
        System.out.println("最小跳跃数："+jump);
        int[] cloudArray2 = {0,0,0,0,1,0};
        int jump2 = clouds.jump(6, cloudArray2);
        System.out.println(6);
        System.out.println(Arrays.toString(cloudArray2));
        System.out.println("最小跳跃数："+jump2);
    }

}
